//
//  LGMedicineRecordCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/7/18.
//

#import "LGMedicineRecordCell.h"

@interface LGMedicineRecordCell()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UILabel *statusLabel;
/**   */
@property (nonatomic , strong)UILabel *contentLabel;

@end

@implementation LGMedicineRecordCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    NSString *content = [NSString stringWithFormat:@"%@ , %@%@ , %@ , %@",dataDic[@"title"],dataDic[@"dose"],dataDic[@"dose_unit"],dataDic[@"take_method"],dataDic[@"take_frequency"]];
    self.contentLabel.text = content;
    NSMutableAttributedString *attrbutString = [[NSMutableAttributedString alloc]initWithString:content];
    //20：已调整  30：停药  10：新增  空是没有状态
    self.statusLabel.hidden = NO;
    CGFloat leftMargin = viewPix(74);
    if([LGNSString(dataDic[@"state"]) isEqualToString:@"20"]){
        self.statusLabel.text = @"已调整";
        self.statusLabel.textColor = [UIColor colorWithString:@"#7BC4B4"];
        self.statusLabel.backgroundColor = [UIColor colorWithString:@"#EFFFF0"];
     
        
    }else if ([LGNSString(dataDic[@"state"]) isEqualToString:@"30"]){
        self.statusLabel.text = @"停药";
        self.statusLabel.textColor = [UIColor colorWithString:@"#DD3030"];
        self.statusLabel.backgroundColor = [UIColor colorWithString:@"#FFDADA"];
        [attrbutString addAttributes:@{NSStrikethroughStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleSingle]} range:NSMakeRange(0, content.length)];
        
    }else if ([LGNSString(dataDic[@"state"]) isEqualToString:@"10"]){
        self.statusLabel.text = @"新增";
        self.statusLabel.textColor = [UIColor colorWithString:@"#3291FF"];
        self.statusLabel.backgroundColor = [UIColor colorWithString:@"#D7E9FF"];
  
    }else{
        self.statusLabel.hidden = YES;
        leftMargin = viewPix(12);
    }
    self.contentLabel.attributedText = attrbutString;
    [self.contentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.baseView).offset(leftMargin);
    }];
}



#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.clipsToBounds = YES;
    self.contentView.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
    [self.contentView addSubview:self.baseView];
    [self.baseView addSubview:self.statusLabel];
    [self.baseView addSubview:self.contentLabel];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.contentView);
        make.left.equalTo(self.contentView).offset(viewPix(16));
        make.right.equalTo(self.contentView).offset(-viewPix(16));
    }];
    [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.baseView).offset(viewPix(6));
        make.width.equalTo(@(52));
        make.height.equalTo(@(20));
    }];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.baseView).offset(viewPix(6));
        make.left.equalTo(self.baseView).offset(viewPix(12));
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.bottom.equalTo(self.baseView).offset(-viewPix(6));
    }];
    
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.15 radius:0];
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}

-(UILabel *)statusLabel{
    if(!_statusLabel){
        _statusLabel = [UILabel lableWithText:@"" colorString:@"" textFont:LGFont(12) textAlignment:NSTextAlignmentCenter lines:1];
        _statusLabel.cornerRidus = 10;
    }
    return _statusLabel;
}

-(UILabel *)contentLabel{
    if(!_contentLabel){
        _contentLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _contentLabel;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
